<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp" />
         <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="css/style.css"/>       
        <link href="assets/css/codemirror.css" rel="stylesheet">
        <link rel="stylesheet" href="assets/css/ace.min.css" />
        <link rel="stylesheet" href="font/css/font-awesome.min.css" />
        <!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->
		<script src="js/jquery-1.9.1.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="Widget/Validform/5.3.2/Validform.min.js"></script>
		<script src="assets/js/typeahead-bs2.min.js"></script>           	
		<script src="assets/js/jquery.dataTables.min.js"></script>
		<script src="assets/js/jquery.dataTables.bootstrap.js"></script>
        <script src="assets/layer/layer.js" type="text/javascript" ></script>          
		<script src="js/lrtk.js" type="text/javascript" ></script>
         <script src="assets/layer/layer.js" type="text/javascript"></script>	
        <script src="assets/laydate/laydate.js" type="text/javascript"></script>
<title>管理员</title>
</head>

<body>
<div class="page-content clearfix">
  <div class="administrator">
       <div class="d_Confirm_Order_style">
    <div class="search_style">
     
      <ul class="search_content clearfix">
       <li><label class="l_f">管理员名称</label><input name="" type="text"  id="text" class="text_add" placeholder=""  style=" width:400px"/></li>
       <li><label class="l_f">添加时间</label><input class="inline laydate-icon" id="start" style=" margin-left:10px;"></li>
       <li style="width:90px;"><button type="button" class="btn_search" onclick="searchManager()"><i class="fa fa-search"></i>查询</button></li>
      </ul>
    </div>
    <!--操作-->
     <div class="border clearfix">
       <span class="l_f">
        <a href="javascript:void(0)" id="administrator_add" class="btn btn-warning"><i class="fa fa-plus"></i> 添加管理员</a>
<!--        <a href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash"></i> 批量删除</a>-->
       </span>
       <span class="r_f">共：<b id="sum"></b>人</span>
     </div>
     <!--管理员列表-->
     <div class="clearfix administrator_style" id="administrator">
      <div class="left_style">
      <div id="scrollsidebar" class="left_Treeview">
        <div class="show_btn" id="rightArrow"><span></span></div>
        <div class="widget-box side_content" >
         <div class="side_title"><a title="隐藏" class="close_btn"><span></span></a></div>
         <div class="side_list"><div class="widget-header header-color-green2"><h4 class="lighter smaller">管理员分类列表</h4></div>
         <div class="widget-body">
           <ul class="b_P_Sort_list">
           <li><i class="fa fa-users green"></i> <a href="#" id="managerSum" onclick="managerAll()">全部管理员</a></li>
            <li><i class="fa fa-users orange"></i> <a href="#" id="supManagerNum" onclick="supManager()">超级管理员</a></li>
            <li><i class="fa fa-users orange"></i> <a href="#" id="managerNum" onclick="manager()">普通管理员</a></li>
<!--            <li><i class="fa fa-users orange"></i> <a href="#">产品编辑管理员（4）</a></li>-->
<!--            <li><i class="fa fa-users orange"></i> <a href="#">管理员（1）</a></li>-->
           </ul>
        </div>
       </div>
      </div>  
      </div>
      </div>
      <div class="table_menu_list"  id="testIframe">
           <table class="table table-striped table-bordered table-hover" id="sample_table">
		<thead>
		 <tr>
<!--				<th width="25px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>-->
				<th width="80px">编号</th>
				<th width="250px">登录名</th>
				<th width="100px">手机</th>
				<th width="100px">邮箱</th>
                <th width="100px">角色</th>				
				<th width="180px">加入时间</th>
				<th width="70px">状态</th>                
				<th width="200px">操作</th>
			</tr>
		</thead>
	<tbody id="managerTbody">
    </tbody>
    </table>
      </div>
     </div>
  </div>
</div>
 <!--添加管理员-->
 <div id="add_administrator_style" class="add_menber" style="display:none">
    <form action="" method="post" id="form-admin-add">
		<div class="form-group">
			<label class="form-label"><span class="c-red">*</span>管理员：</label>
			<div class="formControls">
				<input type="text" class="input-text" value="" placeholder="" id="user-name" name="user-name"  datatype="*2-16" nullmsg="用户名不能为空" errormsg = "用户名已存在">
			</div>
			<div class="col-4"> <span id="span1" class="Validform_checktip"></span></div>
		</div>
		<div class="form-group">
			<label class="form-label"><span class="c-red">*</span>初始密码：</label>
			<div class="formControls">
			<input type="password" placeholder="密码" name="userpassword" autocomplete="off" value="" id="password" class="input-text" datatype="*6-20" nullmsg="密码不能为空">
			</div>
			<div class="col-4"> <span id="span2" class="Validform_checktip"></span></div>
		</div>
		<div class="form-group" id="affirmPwdBox">
			<label class="form-label "><span class="c-red">*</span>确认密码：</label>
			<div class="formControls ">
		<input type="password" placeholder="确认新密码" autocomplete="off" class="input-text Validform_error" errormsg="您两次输入的新密码不一致！" datatype="*" nullmsg="请再输入一次新密码！" recheck="userpassword" id="newpassword2" name="newpassword2">
			</div>
			<div class="col-4"> <span id="span3" class="Validform_checktip"></span></div>
		</div>
		<div class="form-group">
			<label class="form-label "><span class="c-red">*</span>性别：</label>
			<div class="formControls  skin-minimal">
<!--		      <label><input name="form-field-radio" type="radio" class="ace" checked="checked"><span class="lbl">保密</span></label>&nbsp;&nbsp;-->
            <label><input name="form-field-radio" type="radio" class="ace" value="1"><span class="lbl">男</span></label>&nbsp;&nbsp;
            <label><input name="form-field-radio" type="radio" class="ace" value="0"><span class="lbl">女</span></label>
			</div>
			<div class="col-4"> <span class="Validform_checktip"></span></div>
		</div>
		<div class="form-group">
			<label class="form-label "><span class="c-red">*</span>手机：</label>
			<div class="formControls ">
				<input type="text" class="input-text" value="" placeholder="" id="user-tel" name="user-tel" datatype="m" nullmsg="手机不能为空">
			</div>
			<div class="col-4"> <span id="span4" class="Validform_checktip"></span></div>
		</div>
		<div class="form-group">
			<label class="form-label"><span class="c-red">*</span>邮箱：</label>
			<div class="formControls ">
				<input type="text" class="input-text" placeholder="@" name="email" id="email" datatype="e" nullmsg="请输入邮箱！">
			</div>
			<div class="col-4"> <span id="span5" class="Validform_checktip"></span></div>
		</div>
<!--		<div class="form-group">-->
<!--			<label class="form-label">角色：</label>-->
<!--			<div class="formControls "> <span class="select-box" style="width:150px;">-->
<!--				<select class="select" name="admin-role" size="1">-->
<!--					<option value="0">超级管理员</option>-->
<!--					<option value="1">管理员</option>-->
<!--					<option value="2">栏目主辑</option>-->
<!--					<option value="3">栏目编辑</option>-->
<!--				</select>-->
<!--				</span> </div>-->
<!--		</div>-->
<!--		<div class="form-group">-->
<!--			<label class="form-label">备注：</label>-->
<!--			<div class="formControls">-->
<!--				<textarea name="" cols="" rows="" class="textarea" placeholder="说点什么...100个字符以内" dragonfly="true" onkeyup="checkLength(this);"></textarea>-->
<!--				<span class="wordage">剩余字数：<span id="sy" style="color:Red;">100</span>字</span>-->
<!--			</div>-->
<!--			<div class="col-4"> </div>-->
<!--		</div>-->
		<div id="btnBox">
        <input class="btn btn-primary radius"  onclick="put()" type="submit" id="Add_Administrator" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			<input type="reset"  class="btn btn-primary radius"/>
        </div>
	</form>
   </div>
 </div>
</body>
</html>
<script type="text/javascript">
    var managerSum = 0;
    var supMangerNum = 0;
    var managerNum = 0;
    //信息展示
    function info(datas) {
        var tbody = document.getElementById("managerTbody").childNodes;
        if (tbody != null){
            $("#managerTbody").empty();
        }
        if (managerSum == '0'){
			managerSum = datas.length;
		}
        for (i of datas){
        	var jsonObj = JSON.stringify(i);
            var type = "";
            var time = new Date(i.manageTime.time).toLocaleDateString();
            var stopText = "";		//文字
            var stopClass = "";		//类名
            var stopClick = "";     //点击方法
			var editClick = "";		//编辑按钮
			var nameAdd = "";		//编辑跳转地址
			var stopTitle = "";		//a标签title
			var aStopClass = "";   //a标签class
			var iClass = "";       //i标签class
            if (i.manageStatus == '1'){  //判断状态
            	stopText = "已启用";
            	stopClass = 'label label-success radius';
            	stopClick = "member_stop(this,"+i.managerId+")";
            	stopTitle = "停用";
            	aStopClass = 'btn btn-xs btn-success';
				iClass = 'fa fa-check  bigger-120';
			}else {
            	stopText = "已停用";
            	stopClass = 'label label-defaunt radius';
            	stopClick = "member_start(this,"+i.managerId+")";
            	stopTitle = "启用";
            	aStopClass = 'btn btn-xs';
            	iClass = 'fa fa-close bigger-120';
			}
			if (i.manageType == '1'){
				type = "超级管理员";
				supMangerNum += 1;
				stopClick = "void(0)";
				editClick = "void(0)";
				nameAdd = "admin_info.html";
			}else {
				type = "普通管理员";
				managerNum += 1;
				editClick = "managerEdit("+ i.managerId +",\""+i.managerName+"\","+  i.managerPassword +","+  i.manageSex +","+ i.manageIphone +",\""+ i.manageEmail +"\")";
				nameAdd = "";
			}
            var tr = document.createElement("tr");
            tr.innerHTML=
                "<td>"+ i.managerId +"</td>"+
                "<td>"+ i.managerName +"</td>"+
                "<td>"+ i.manageIphone +"</td>"+
                "<td>"+ i.manageEmail +"</td>"+
                "<td>"+ type +"</td>"+
                "<td>"+ time +"</td>"+
                "<td class=\"td-status\"><span class=\""+ stopClass +"\">"+ stopText +"</span></td>\n" +
                "      <td class=\"td-manage\">\n" +
                "        <a onClick="+ stopClick +" href=\"javascript:void(0)\" title="+ stopTitle +"  class=\""+ aStopClass +"\"><i class=\""+ iClass +"\"></i></a>   \n" +
                "        <a onclick="+ editClick +" href=\"javascript:void(0)\" title=\"编辑\" class=\"btn btn-xs btn-info\" name="+ nameAdd +" ><i class=\"fa fa-edit bigger-120\"></i></a>\n" +
                "       </td>"
            $("#managerTbody").append(tr);
        }
    }
    //单个信息展示
    function oneInfo(obj) {
		var tbody = document.getElementById("managerTbody").childNodes;
		if (tbody != null){
			$("#managerTbody").empty();
		}
		var i = obj.managers.object;
		var jsonObj = JSON.stringify(i);
		var type = "";
		var time = new Date(i.manageTime.time).toLocaleDateString();
		var stopText = "";		//文字
		var stopClass = "";		//类名
		var stopClick = "";     //点击方法
		var editClick = "";		//编辑按钮
		var nameAdd = "";		//编辑跳转地址
		var stopTitle = "";		//a标签title
		var aStopClass = "";   //a标签class
		var iClass = "";       //i标签class
		if (i.manageStatus == '1'){  //判断状态
			stopText = "已启用";
			stopClass = 'label label-success radius';
			stopClick = "member_stop(this,"+i.managerId+")";
			stopTitle = "停用";
			aStopClass = 'btn btn-xs btn-success';
			iClass = 'fa fa-check  bigger-120';
		}else {
			stopText = "已停用";
			stopClass = 'label label-defaunt radius';
			stopClick = "member_start(this,"+i.managerId+")";
			stopTitle = "启用";
			aStopClass = 'btn btn-xs';
			iClass = 'fa fa-close bigger-120';
		}
		if (i.manageType == '1'){
			type = "超级管理员";
			stopClick = "";
			editClick = "";
			nameAdd = "admin_info.html";
		}else {
			type = "普通管理员";
			editClick = "managerEdit("+ i.managerId +",\""+i.managerName+"\","+  i.managerPassword +","+  i.manageSex +","+ i.manageIphone +",\""+ i.manageEmail +"\")";
			nameAdd = "";
		}
		var tr = document.createElement("tr");
		tr.innerHTML=
				"<td>"+ i.managerId +"</td>"+
				"<td>"+ i.managerName +"</td>"+
				"<td>"+ i.manageIphone +"</td>"+
				"<td>"+ i.manageEmail +"</td>"+
				"<td>"+ type +"</td>"+
				"<td>"+ time +"</td>"+
				"<td class=\"td-status\"><span class=\""+ stopClass +"\">"+ stopText +"</span></td>\n" +
				"      <td class=\"td-manage\">\n" +
				"        <a onClick="+ stopClick +"  href=\"javascript:;\" title="+ stopTitle +"  class=\""+ aStopClass +"\"><i class=\""+ iClass +"\"></i></a>   \n" +
				"        <a onclick="+ editClick +"  href=\"javascript:;\" title=\"编辑\" name="+ nameAdd +" class=\"btn btn-xs btn-info\" ><i class=\"fa fa-edit bigger-120\"></i></a>\n" +
				"       </td>"
		$("#managerTbody").append(tr);
	}
    function search(url,page) {
        $.ajax({
            url: url,
            data:{
                currentPage:page,
                pageSize:10
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                var obj = JSON.parse(data);
                console.log(obj);
                if (obj.managers.message == '200'){
                    info(obj.managers.object.datas);
                }
            },
            error:function (data){
            }
        });
    }
    var page = 1;

    $.ajax({
        url: "http://localhost:8080/SnacksShop/supManager.do?type=queryAllManager",
        data:{
            currentPage:page,
            pageSize:10
        },
        crossDomain: true,
        xhrFields: {
            withCredentials: true
        },
        type: "post",
        success:function (data){
            var obj = JSON.parse(data);
            if (obj.managers.message == '200'){
                info(obj.managers.object.datas);
                $("#managerSum").text($("#managerSum").text()+"("+managerSum+")");
                $("#supManagerNum").text($("#supManagerNum").text()+"("+supMangerNum+")");
                $("#managerNum").text($("#managerNum").text()+"("+managerNum+")");
				$("#sum").text($("#sum").text()+managerSum);
            }
        },
        error:function (data){

        }
    });
    // search(url,page);
jQuery(function($) {
		var oTable1 = $('#sample_table').dataTable( {
		"aaSorting": [[ 1, "desc" ]],//默认第几个排序
		"bStateSave": true,//状态保存
		"aoColumnDefs": [
		  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		  {"orderable":false,"aTargets":[0,2,3,4,5,7,8,]}// 制定列不参与排序
		] } );
				
				
				$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
				});
			
			
				$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
				function tooltip_placement(context, source) {
					var $source = $(source);
					var $parent = $source.closest('table')
					var off1 = $parent.offset();
					var w1 = $parent.width();
			
					var off2 = $source.offset();
					var w2 = $source.width();
			
					if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
					return 'left';
				}
			});

</script>
<script type="text/javascript">
$(function() { 
	$("#administrator").fix({
		float : 'left',
		//minStatue : true,
		skin : 'green',	
		durationTime :false,
		spacingw:50,//设置隐藏时的距离
	    spacingh:270,//设置显示时间距
	});
});
//字数限制
function checkLength(which) {
	var maxChars = 100; //
	if(which.value.length > maxChars){
	   layer.open({
	   icon:2,
	   title:'提示框',
	   content:'您输入的字数超过限制!',	
    });
		// 超过限制的字数了就将 文本框中的内容按规定的字数 截取
		which.value = which.value.substring(0,maxChars);
		return false;
	}else{
		var curr = maxChars - which.value.length; //250 减去 当前输入的
		document.getElementById("sy").innerHTML = curr.toString();
		return true;
	}
};
//初始化宽度、高度  
 $(".widget-box").height($(window).height()-215); 
$(".table_menu_list").width($(window).width()-260);
 $(".table_menu_list").height($(window).height()-215);
  //当文档窗口发生改变时 触发  
    $(window).resize(function(){
	$(".widget-box").height($(window).height()-215);
	 $(".table_menu_list").width($(window).width()-260);
	  $(".table_menu_list").height($(window).height()-215);
	})
 laydate({
    elem: '#start',
    event: 'focus' 
});

    function userStatus(urlStatus,id,msg) {
		$.ajax({
			url: "http://localhost:8080/SnacksShop/supManager.do?type="+urlStatus,
			type: "post",
			data:{
				id:id,
			},
			crossDomain: true,
			xhrFields: {
				withCredentials: true
			},
			type: "post",
			success:function (data){
				msg;
			},
			error:function (data){

			}
		});
	}
/*用户-停用*/
function member_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onClick="member_start(this,'+id+')" href="javascript:;" title="启用"><i class="fa fa-close bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
		$(obj).remove();
		userStatus('stop',id,layer.msg('已停用!',{icon: 5,time:1000}));
		// layer.msg('已停用!',{icon: 5,time:1000});
	});
}
/*用户-启用*/
function member_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,'+id+')" href="javascript:;" title="停用"><i class="fa fa-check  bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
		$(obj).remove();
		userStatus('start',id,layer.msg('已启用!',{icon: 6,time:1000}));
		// layer.msg('已启用!',{icon: 6,time:1000});
	});
}
/*产品-编辑*/
function member_edit(title,url,id,w,h){
	// layer_show(title,url,w,h);
}

//编辑管理员信息
function managerEdit(id,name,pwd,sex,iphone,email) {
	console.log("编辑");
	layer.open({
		type: 1,
		title:'编辑管理员',
		area: ['700px',''],
		shadeClose: false,
		content: $('#add_administrator_style'),
	});
	$("#user-name").val(name);
	$("#user-name").attr("value",name);
	$("input[name=userpassword]").val(pwd);
	if (sex == '1'){
		$("input[value='1']").attr("checked","checked");
	}else {
		$("input[value='0']").attr("checked","checked");
	}
	$("#user-tel").val(iphone);
	$("#user-tel").attr("value",iphone);
	$("#email").val(email);
	$("#email").attr("value",email);
	document.getElementById("affirmPwdBox").style.display = "none";
	$("#password").attr("type","text");
	$("#Add_Administrator").attr("onclick","edit("+ id +")");
}
	//编辑信息提交
	function edit(id) {
		var username = $("#user-name").val();
		var password = $("#password").val();
		var sex = $("input[name=form-field-radio]:checked").val();
		console.log("性别:"+sex);
		var userTel = $("#user-tel").val();
		var email = $("#email").val();
		var url = "http://localhost:8080/SnacksShop/supManager.do?type=updateManager";
		updateManger(id,username,password,sex,userTel,email,url,"修改成功!","修改失败");
	}

/*产品-删除*/
function member_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$(obj).parents("tr").remove();
		layer.msg('已删除!',{icon:1,time:1000});
	});
}
/*添加管理员*/
$('#administrator_add').on('click', function(){
	layer.open({
    type: 1,
	title:'添加管理员',
	area: ['700px',''],
	shadeClose: false,
	content: $('#add_administrator_style'),
	});
	$("#Add_Administrator").attr("onclick","put()");
});

	//表单验证提交
$("#form-admin-add").Validform({

    tiptype: 2,

   lback: function (data) {
        //form[0].submit();
        if (data.status == 1) {
            layer.msg(data.info, {icon: data.status, time: 1000}, function () {
                location.reload();//刷新页面
            });
        } else {
            layer.msg(data.info, {icon: data.status, time: 3000});
        }
        var index = parent.$("#iframe").attr("src");
        parent.layer.close(index);
        //
    }


});

	var exitUsername = false;
	var exitUserTel = false;
	var exitUserEmail = false;
	//判断管理员是否存在
	document.getElementById("user-name").addEventListener("blur",function (){
		var usernameValue = $("#user-name").attr("value");
		var username = $("#user-name").val();
		var element = $("#span1");
		if (username != usernameValue){
			var errorText = "用户名已存在";
			exitManager(username,element,errorText);
		}
		element.attr("value",false);
		// $("#user-name").attr("value","");
	});
	//判断手机号是否存在
	document.getElementById("user-tel").addEventListener("blur",function (){
		var userTelValue = $("#user-tel").attr("value");
		var userTel = $("#user-tel").val();
		var element = $("#span4");
		if (userTelValue != userTel){
			var errorText = "手机号码已存在";
			exitManager(userTel,element,errorText);
		}
		element.attr("value",false);
		// $("#user-tel").attr("value","");
	});
	//判断邮箱是否存在
	document.getElementById("email").addEventListener("blur",function (){
		var emailValue = $("#email").attr("value");
		var email = $("#email").val();
		var element = $("#span5");
		if(email != emailValue){
			var errorText = "邮箱已存在";
			exitManager(email,element,errorText);
		}
		element.attr("value",false);
		// $("#email").attr("value","");
	});
	//验证管理员是否存在
	function exitManager(value,element,errorText) {
		$.ajax({
			url: "http://localhost:8080/SnacksShop/supManager.do?type=exitManager",
			data:{
				managerInfo:value,
			},
			crossDomain: true,
			xhrFields: {
				withCredentials: true
			},
			type: "post",
			success:function (data){
				var obj = JSON.parse(data);
				if (obj.result == true){
					element.attr("class","Validform_checktip Validform_wrong");
					element.text(errorText);
					element.attr("value",true);
				}else {
					element.attr("value",false);
				}
			},
			error:function (data){
				console.log("失败");
			}
		});
	};


	//添加管理员提交按钮选中事件
	document.getElementById("Add_Administrator").addEventListener("mouseenter",function (){
		var nameSpan = $("#span1").attr("value");
		var telSpan = $("#span4").attr("value");
		var emailSpan = $("#span5").attr("value");
		if (nameSpan == 'true' || telSpan == 'true' || emailSpan == 'true'){
			document.getElementById("Add_Administrator").disabled = true;
		}
	});
	document.getElementById("btnBox").addEventListener("mouseleave",function (){
		document.getElementById("Add_Administrator").disabled = false;
	});
	//添加管理员提交按钮点击事件
	function put() {
		var username = $("#user-name").val();
		var password = $("#password").val();
		var sex = $("input[name=form-field-radio]:checked").val();
		var userTel = $("#user-tel").val();
		var email = $("#email").val();
		var url = "http://localhost:8080/SnacksShop/supManager.do?type=addManager";
		updateManger(null,username,password,sex,userTel,email,url,"添加成功!","添加失败");
	};
	//添加和修改管理员信息的异步请求方法
	function updateManger(id,username,pwd,sex,iphone,email,url,successText,errorText) {
		$.ajax({
			url: url,
			data:{
				id:id,
				username:username,
				password:pwd,
				sex:sex,
				userTel:iphone,
				email:email
			},
			crossDomain: true,
			xhrFields: {
				withCredentials: true
			},
			type: "post",
			success:function (data){
				var obj = JSON.parse(data);
				if (obj == '200'){
					layer.alert(successText+"\r\n",{
						title: '提示框',
						icon:1,
					});
				}else {
					layer.alert(errorText+"\r\n",{
						title: '提示框',
						icon:0,
					});
				}
			},
			error:function (data){
				layer.alert("无法连接服务器 \r\n",{
					title: '提示框',
					icon:0,
				});
			}
		});
	}
	//查询所有所有管理员
	function managerAll() {
		var url = "http://localhost:8080/SnacksShop/supManager.do?type=queryAllManager";
		search(url,1);
	}
	//查询超级管理员
	function supManager() {
		var url = "http://localhost:8080/SnacksShop/supManager.do?type=supManager";
		$.ajax({
			url: url,
			data:{
				currentPage:1,
				pageSize:10
			},
			crossDomain: true,
			xhrFields: {
				withCredentials: true
			},
			type: "post",
			success:function (data){
				var obj = JSON.parse(data);
				if (obj.managers.message == '200'){
					oneInfo(obj);
				}
			},
			error:function (data){
			}
		});
	}
	//查询普通管理员
	function manager() {
		var url = "http://localhost:8080/SnacksShop/supManager.do?type=manager";
		search(url,1);
	}
	//搜索管理员
	function searchManager() {
		var managerName = $("#text").val();
		var managerTime = $("#start").val();
		if (managerName != "" && managerTime == ""){
			//根据名字查询
			queryManagerName(managerName);
		}else if (managerName == "" && managerTime != ""){
			//根据时间查询
			queryManagerTime(managerTime);
		}else if (managerName != "" && managerTime != ""){
			//根据名字和时间
			queryManagerByNameAndTime(managerName,managerTime);
		}else {
			layer.alert("条件为空 \r\n",{
				title: '提示框',
				icon:0,
			});
		}
	}
	//根据名字查询
	function queryManagerName(name) {
		$.ajax({
			url: "http://localhost:8080/SnacksShop/supManager.do?type=queryByNameManager",
			type: "post",
			data:{
				searchText:name,
				currentPage:1,
				pageSize:10
			},
			crossDomain: true,
			xhrFields: {
				withCredentials: true
			},
			type: "post",
			success:function (data){
				var obj = JSON.parse(data);
				console.log(obj);
				if (obj.managers.message == '200'){
					info(obj.managers.object.datas);
				}else {
					layer.alert("没有您想要的结果 \r\n",{
						title: '提示框',
						icon:0,
					});
				}
			},
			error:function (data){

			}
		});
	}
	//根据时间查询
	function queryManagerTime(time) {
		$.ajax({
			url: "http://localhost:8080/SnacksShop/supManager.do?type=queryByTimeManager",
			type: "post",
			data:{
				searchDate:time,
				currentPage:1,
				pageSize:10
			},
			crossDomain: true,
			xhrFields: {
				withCredentials: true
			},
			type: "post",
			success:function (data){
				var obj = JSON.parse(data);
				if (obj.managers.message == '200'){
					info(obj.managers.object.datas);
				}else {
					layer.alert("没有您想要的结果 \r\n",{
						title: '提示框',
						icon:0,
					});
				}
			},
			error:function (data){

			}
		});
	}
	//根据名字和时间查询
	function queryManagerByNameAndTime(name,time) {
		$.ajax({
			url: "http://localhost:8080/SnacksShop/supManager.do?type=queryByNameAndTimeManager",
			type: "post",
			data:{
				searchText:name,
				searchDate:time,
				currentPage:1,
				pageSize:10
			},
			crossDomain: true,
			xhrFields: {
				withCredentials: true
			},
			type: "post",
			success:function (data){
				var obj = JSON.parse(data);
				if (obj.managers.message == '200'){
					info(obj.managers.object.datas);
				}else {
					layer.alert("没有您想要的结果 \r\n",{
						title: '提示框',
						icon:0,
					});
				}
			},
			error:function (data){

			}
		});
	}

</script>

